<template>
	<!--小区网关列表-->
	<view>
		<view class="community">
			<view class="head_bg">
				<view class="community_msg">
					<view class="community_msg_line" style="margin-top: 0;">
						<image class="community_msg_icon" src="../../../common/img/gongsi_bai.png" mode=""></image>
						<text class="community_msg_text">{{info.residential_quarters_name}}</text>
					</view>
					<view class="community_msg_line" style="margin-top: 0;">
						<image class="community_msg_icon" src="../../../common/img/dizhi_bai.png" mode=""></image>
						<text class="community_msg_text">{{info.residential_quarters_address}}</text>
					</view>
				</view>
			</view>
			<view class="big_box" >
				<view class="big_box_inner" v-for="(info,index) in list" :key="index" style="margin-top:20px;">
					<view class="equ_list" @tap="toEquDetail">
						<view class="equ_list_title">
							<view class="equ_list_title_left">
								<text>网关编号：{{info.gateway_sn}}</text>
							</view>
						</view>
						<view class="operating_box_inner">
							<view class="money_details_inner money_details_inner1">
								<view class="money_details_number" style="color: #333333;">{{info.device_total}}</view>
								<view class="money_details_text" style="color: #666666;">插座个数(个)</view>
							</view>
							<!-- <view class="detail_br" style="border-left: 1rpx solid #EDEDED;position: relative;top: 25rpx;"></view> -->
							<view class="money_details_inner money_details_inner1">
								<view class="money_details_number" style="color: #333333;">{{info.device_normal_total}}</view>
								<view class="money_details_text" style="color: #666666;">正常个数(个)</view>
							</view>
							<!-- <view class="detail_br" style="border-left: 1rpx solid #EDEDED;position: relative;top: 25rpx;"></view> -->
							<view class="money_details_inner money_details_inner1">
								<view class="money_details_number" style="color: #333333;">{{info.device_fault_total}}</view>
								<view class="money_details_text" style="color: #666666;">故障个数(个)</view>
							</view>
						</view>
						<view class="operating_box_inner">
							<view class="money_details_inner money_details_inner1">
								<view class="money_details_number" style="color: #333333;">{{info.device_online_total}}</view>
								<view class="money_details_text" style="color: #666666;">在线个数(个)</view>
							</view>
							<!-- <view class="detail_br" style="border-left: 1rpx solid #EDEDED;position: relative;top: 25rpx;"></view> -->
							<view class="money_details_inner money_details_inner1">
								<view class="money_details_number" style="color: #333333;">{{info.device_off_total}}</view>
								<view class="money_details_text" style="color: #666666;">离线个数(个)</view>
							</view>
							<!-- <view class="detail_br" style="border-left: 1rpx solid #EDEDED;position: relative;top: 25rpx;"></view> -->
							<view class="money_details_inner money_details_inner1">
								<view class="money_details_number" style="color: #333333;">{{info.device_user_total}}</view>
								<view class="money_details_text" style="color: #666666;">正在使用(个)</view>
							</view>
						</view>
						<view class="remarks" style="color: #666666;">
							<image src="../../../common/img/beizhu.png" class="remard-img"></image>
							<text style="vertical-align: middle;">备注:{{info.remark?"nfo.remark":'暂无备注信息'}}</text>
							</view>
						<!-- <view class="equ_list_inner1">
							<view class="equ_list_inner_text1">插座个数:{{info.device_total}}个</view>
							<view class="equ_list_inner_text1">正常个数:{{info.device_normal_total}}个</view>
							<view class="equ_list_inner_text1">故障个数:{{info.device_fault_total}}个</view>
							<view class="equ_list_inner_text1">在线个数:{{info.device_online_total}}个</view>
							<view class="equ_list_inner_text1">离线个数:{{info.device_off_total}}个</view>
							<view class="equ_list_inner_text1">正在使用:{{info.device_user_total}}个</view>
						</view> -->
						
						<view class="gateway_bottom">
							<!-- <view class="ele_add">修改</view> -->
							<view class="ele_add" @tap="delway(info.gateway_sn)" 
							style="background: #DD524D;margin-left: 30rpx;margin-right: 30rpx;">删除</view>
						</view>
					</view>
				</view>
			</view>
			<view style="height:100rpx;"></view>
			<view v-if="list.length==0" class="margin-top-lg text-center">
				<image src='../../../common/img/no_data.png' style="width:275rpx;height:312rpx;"></image>
			</view>
			<!-- <view v-if="list.length>0" class="text-black text-df text-center bg-white padding-sm padding-left-lg be-gray">
				{{loadingTxt}} 共({{totle}}条记录)
			</view> -->
		</view>
		<image @tap="toAdd" class="add_btn" src="../../../common/img/tianjia.png" mode=""></image>
	</view>
</template>

<script>
	let page=1,timer=null
	export default {
		data() {
			return {
				list:[],
				total:0,
				name:'',
				info:"",
				loadingTxt:'加载更多',
			}
		},
		onLoad(options) {
			let info=JSON.parse(options.item);
			this.info=info;
		},
		onShow() {
			page=1;
			this.getlist();
		},
		methods: {
			toAdd(){
				uni.navigateTo({
					url: '/pages/gateway/addGateway/addGateway?item='+JSON.stringify(this.info)
				})
			},
			getlist(){
				let that=this;
				that.http.tokenreq({
					url: 'gateway/v1/list',
					data: {
				    "pageindex":page,
					'residential_quarters_guid':this.info.residential_quarters_guid
					}
				}).then((res) => {
					let e=res.data;
					console.log(JSON.stringify(e.rows));
					if(e.code==0 && e.success){
						this.list = e.rows;
						this.totle= e.total;
						page++
					}
				})
			},
			getmorelist(){
				this.loadingTxt='加载中'
				let that=this;
				that.http.tokenreq({
					url: 'gateway/v1/list',
					data: {
					"pageindex":page,
					'residential_quarters_guid':this.info.residential_quarters_guid
					}
				}).then((res) => {
					console.log("res="+JSON.stringify(res));
					let e=res.data;
					if(e.code==0 && e.success){
						if(e.rows.length==0){
							that.loadingTxt="已经加载全部";
							return;
						}
						that.list=that.list.concat(e.rows);
						page++;
					}else{
						uni.showModal({
							content:e.message,
							showCancel:false,
						})
					}
				})
			},
			onReachBottom() {
				//阻止重复加载
				if(timer !== null){
					clearTimeout(timer)
				}
				timer=setTimeout(()=>this.getmorelist(),500)
			},
			//删除网关
			delway(number){
				let that=this;
				uni.showModal({
					title: '提示',
					content: '确定要删除该网关信息吗?',
					success: function (res) {
						if (res.confirm) {
							that.suredel(number);
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			suredel(number){
				let that=this;
				uni.showLoading();
				that.http.tokenreq({
					url: 'gateway/v1/del',
					data:{"gateway_sn":number}
				}).then((res) => {
					console.log("res="+JSON.stringify(res));
					let e=res.data;
					if(e.code==0 && e.success){
						uni.hideLoading();
						uni.showModal({
							content: e.message,
							showCancel:false,
							success: function (res) {
								if (res.confirm) {
									that.getlist()
								}
							}
						});
					}else{
						uni.showModal({
							content:e.message,
							showCancel:false,
						})
					}
				})
			}
		}
	}
</script>

<style>
 .big_box{
	 top:-60rpx
 }
 .remarks{
	 padding: 20rpx 0 0 50rpx ;
 }
 .remard-img{
	 width: 35rpx;
	 height: 35rpx;
	 margin-right: 10rpx;
	 vertical-align: middle;
 }
</style>
